package com.nifostasky.blog.controller;

import com.nifostasky.entity.User;
import com.nifostasky.service.impl.UserUtilServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userUtil")
public class UserUtilController {
    @Autowired
    @Qualifier("userUtilService")
    private UserUtilServiceImpl userUtilService;

    @GetMapping("/queryAll")
    public List<User> queryAll() {
        return userUtilService.queryAll();
    }

    @GetMapping("/getUserInfo/{userId}")
    public User getUserInfo(@PathVariable Long userId) {
        return userUtilService.getUserInfo(userId);
    }

    @PostMapping("/add")
    public String add(@RequestBody User user) {
        userUtilService.add(user);
        userUtilService.add(user);
        return "新增成功～";
    }

    @PostMapping("update")
    public String update(@RequestBody User user) {
        userUtilService.update(user);
        return "更新成功～";
    }

    @GetMapping("/delete/{userId}")
    public String delete(@PathVariable Long userId) {
        userUtilService.delete(userId);
        return "删除成功～";
    }
}
